/*
 * Encrypter.java  2009/5/20
 *
 * Copyright (c) 2009 Chin Shan Information Service Co., Ltd
 * All Rights Reserved.
 */
package ijournalimporter.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;



/**
 * Class description goes here.
 *
 * @version EquipFix 1.0
 * @author alan.lin
 */
public class Encrypter {
    
	public static String encrypt(String str) {

		try {
			str = mixNormal(str);
//			KeyGenerator generator = KeyGenerator.getInstance("DES");
//			generator.init(new SecureRandom(key_string.getBytes()));
//			Key key = generator.generateKey();
//			Cipher ecipher = Cipher.getInstance("DES");
//			ecipher.init(Cipher.ENCRYPT_MODE, key);

			// Encode the string into bytes using utf-8
			byte[] utf8 = str.getBytes("UTF8");

			// Encrypt
//			byte[] enc = ecipher.doFinal(utf8);

			// Encode bytes to base64 to get a string
			return new sun.misc.BASE64Encoder().encode(utf8);
		} catch (Exception ex) {
			 Logger.getLogger(Encrypter.class.getName()).log(Level.SEVERE, null, ex);
		}
		return null;
	}
		
	private static String mixNormal(String str) {
		Date currentTime = new Date();
		SimpleDateFormat timeFormatter = new SimpleDateFormat("ssSSS", Locale.TAIWAN);
		String time = timeFormatter.format(currentTime);
		str = time.substring(0, 2) + str + time.substring(2, 5);
		return str;
	}

}

